home *** CD-ROM | disk | FTP | other *** search
/ Day Cry / Day Cry CD.bin / oh_towns / taropyon / splib / splib.lzh / PRG / LHX / LARC.C < prev    next >
C/C++ Source or Header  |  1993-03-04  |  2KB  |  93 lines

  1. /***********************************************************
  2.         larc.c -- extract *.lzs
  3. ***********************************************************/
  4. #include    "lh386.h"
  5.  
  6. #include    <stdio.h>
  7. #include    <string.h>
  8. #include    "slidehuf.h"
  9.  
  10. #ifdef    __HIGHC__
  11. #    pragma    On(Align_labels);
  12. #endif
  13.  
  14.  
  15. #define MAGIC0 18
  16. #define MAGIC5 19
  17.  
  18. static int    flag = 0, flagcnt = 0, matchpos = 0;
  19.  
  20. ushort        decode_c_lzs(void)
  21. {
  22.     if (getbits(1))
  23.     {
  24.         return getbits(8);
  25.     } else
  26.     {
  27.         matchpos = getbits(11);
  28.         return getbits(4) + 0x100;
  29.     }
  30. }
  31.  
  32. ushort        decode_p_lzs(int loc)
  33. {
  34.     return (loc - matchpos - MAGIC0) & 0x7ff;
  35. }
  36.  
  37. void        decode_start_lzs(void)
  38. {
  39.     init_getbits();
  40. }
  41.  
  42. ushort        decode_c_lz5(void)
  43. {
  44.     int         c;
  45.  
  46.     if (flagcnt == 0)
  47.     {
  48.         flagcnt = 8;
  49.         flag = getc(infile) & 0xFF;
  50.     }
  51.     flagcnt--;
  52.     c = getc(infile) & 0xFF;
  53.     if ((flag & 1) == 0)
  54.     {
  55.         matchpos = c;
  56.         c = getc(infile) & 0xFF;
  57.         matchpos += (c & 0xf0) << 4;
  58.         c &= 0x0f;
  59.         c += 0x100;
  60.     }
  61.     flag >>= 1;
  62.     return c;
  63. }
  64.  
  65. ushort        decode_p_lz5(int loc)
  66. {
  67.     return (loc - matchpos - MAGIC5) & 0xfff;
  68. }
  69.  
  70. void        decode_start_lz5(void)
  71. {
  72.     int         i;
  73.  
  74.     flagcnt = 0;
  75.     for (i = 0; i < 256; i++)
  76.         memset(&text[i * 13 + 18], i, 13);
  77.     for (i = 0; i < 256; i++)
  78.         text[256 * 13 + 18 + i] = i;
  79.     for (i = 0; i < 256; i++)
  80.         text[256 * 13 + 256 + 18 + i] = 255 - i;
  81.     memset(&text[256 * 13 + 512 + 18], 0, 128);
  82.     memset(&text[256 * 13 + 512 + 128 + 18], ' ', 128 - 18);
  83. }
  84.  
  85. #ifdef    _STARTUP_INIT
  86. void    larc_ini(void)
  87. {
  88.     flag = 0;
  89.     flagcnt = 0;
  90.     matchpos = 0;
  91. }
  92. #endif
  93.